home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Source Code
/
Pascal
/
Code Resources
/
Eclectic CDEFs
/
Celsius CDEF Folder
/
CalculateBarBoundary Folder
/
CalculateBarBoundary.c
next >
Wrap
C/C++ Source or Header
|
1997-02-28
|
3KB
|
73 lines
#include <Types.h>
#include <Controls.h>
/*
CalculateBarBoundary
Calculates the right edge of the 'done' part of the progress bar, given the bar's edges
and the control handle. This method works if the following conditions hold:
(1) inControlBoxRight >= inControlBoxLeft, and
(2) contrlMax >= contrlValue >= contrlMin.
Both of these should be met in normal circumstances. If these restrictions hold, then the
differences (both in the numerator and the one in the denominator) will fit into 16-bit unsigned
integers. That means that we can use the mulu.w and divu.w instructions to perform the multiply
and divide, instead of requiring the addition of the software library for 32 bit multiplication
on the 68000.
The only other thing to note is that a division by zero can’t happen. The denominator is zero
only when contrlMax == contrlMin. If this is the case, then contrlValue == contrlMin and the
branch before the multiply will be taken, so the division instruction is never reached.
Entry: inControlHdl = handle to control
inControlBoxLeft = left edge of the control's box
inControlBoxRight = right edge of the control's box
Exit: function result = right edge of the 'done' part of the progress bar
Original versions Copyright © by Chris Larson, Andrew Regan
Modifications by Sebastiano Pilla
*/
pascal SInt16 CalculateBarBoundary (ControlHandle inControlHdl,
SInt16 inControlBoxLeft,
SInt16 inControlBoxRight)
{
SInt16 min, max, val, result;
min = (*inControlHdl)->contrlMin;
max = (*inControlHdl)->contrlMax;
val = (*inControlHdl)->contrlValue;
asm
{
move.w inControlBoxRight, D1 // Right edge of the box to D1
move.w inControlBoxLeft, D0 // Left edge of the box to D0
sub.w D0, D1 // Width of the box to D1
move.w val, D2 // Control's value to D2
sub.w min, D2 // Normalized value to D2
beq @Exit // If normalized value == 0, exit
// Note that D0 holds the original
// left edge, which is then picked up
// and put onto the stack by the compiler
mulu.w D2, D1 // Box width * normalized value to D1
move.w max, D2 // Control's max to D2
sub.w min, D2 // Normalized maximum to D2
divu.w D2, D1 // Width * value / max to D1
// Note that division by zero
// can't happen here
add.w D1, D0 // Offset left edge by amount in D1
// Place result in D0 for the compiler
@Exit:
move.w D0, result // Return the result
}
return (result);
}